// xlocnum internal header (from <locale>) -*-c++-*-
// Copyright 2005-2010 IAR Systems AB. 
#ifndef _XLOCNUM_
#define _XLOCNUM_

#ifndef _SYSTEM_BUILD
#pragma system_include
#endif

#include <cerrno>
#include <climits>
#include <clocale>
#include <cstdio>
#include <cstdlib>
#include <streambuf>

// TEXT-TO-NUMERIC CONVERSION FUNCTIONS
#ifdef _LONGLONG
#define _STOLL(buf, ptr, base, perr)  __iar_Stollx(buf, ptr, base, perr)
#define _STOULL(buf, ptr, base, perr) __iar_Stoullx(buf, ptr, base, perr)
#endif /* _LONGLONG */

// MACROS
#define _MAKLOCBYTE(Ty, Val, Cvt)       ((Ty)(Val))     /* convert to byte */
#define _MAKLOCCHR(Ty, Val, Cvt)        ((Ty)(Val))     /* convert from byte */
// Placeholder for non-virtual functions in Embedded C++ that should
// be "virtual" it this would have been full C++.
#define _VIRTUAL

//      FUNCTION _Getloctxt
int __iar_Getloctxt(_Istrit& _First, _Istrit& _Last, size_t _Numfields,
                    const char *_Ptr);

_STD_BEGIN
// CLASS numpunct
class numpunct
{       // facet for defining numeric punctuation text
public:
  typedef string string_type;

  static char decimal_point()
  {       // return decimal point
    return ('.');
  }

  static char thousands_sep()
  {       // return thousands separator
    return ('\0');
  }

  static string grouping()
  {       // return grouping string
    return ("");
  }

  static string_type falsename()
  {       // return false name
    return ("false");
  }

  static string_type truename()
  {       // return true name
    return ("true");
  }
};

// CLASS num_get
class num_get
{       // facet for converting text to encoded numbers
public:
  typedef char _Elem;
  typedef _Istrit _InIt;
  typedef numpunct _Mypunct;
  typedef string _Mystr;

  typedef _Elem char_type;
  typedef _InIt iter_type;

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, _Bool& _Val) const
  {       // get bool from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, unsigned short& _Val) const
  {       // get unsigned short from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, unsigned int& _Val) const
  {       // get unsigned int from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, long& _Val) const
  {       // get long from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, unsigned long& _Val) const
  {       // get unsigned long from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }
#ifdef _LONGLONG
  #pragma language=save
  #pragma language=extended
  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, _LONGLONG& _Val) const
  {       // get long long from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, _ULONGLONG& _Val) const
  {       // get unsigned long long from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }
  #pragma language=restore
#endif /* _LONGLONG */

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, float& _Val) const
  {       // get float from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, double& _Val) const
  {       // get double from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, long double& _Val) const
  {       // get long double from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

  _InIt get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
            ios_base::iostate& _State, void *& _Val) const
  {       // get void pointer from [_First, _Last) into _Val
    return (do_get(_First, _Last, _Iosbase, _State, _Val));
  }

protected:
  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, _Bool& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, unsigned short& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, unsigned int& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, long& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, unsigned long& _Val) const;
#ifdef _LONGLONG
  #pragma language=save
  #pragma language=extended
  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, _LONGLONG& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, _ULONGLONG& _Val) const;
  #pragma language=restore
#endif /* _LONGLONG */

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, float& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, double& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, long double& _Val) const;

  _VIRTUAL _InIt do_get(_InIt _First, _InIt _Last, ios_base& _Iosbase,
                        ios_base::iostate& _State, void *& _Val) const;


private:
  int _Getifld(char *_Ac, _InIt& _First, _InIt& _Last,
               ios_base::fmtflags _Basefield, const locale& _Loc) const;


  int _Getffld(char *_Ac, _InIt& _First, _InIt &_Last,
               ios_base& _Iosbase, int *_Phexpexp) const;

  int _Hexdig(const _Elem _Dig, const _Elem _E0,
              const _Elem _Al, const _Elem _Au) const;

  int _Getffldx(char *_Ac, _InIt& _First, _InIt &_Last,
                ios_base& _Iosbase, int *_Phexexp) const;
};


// CLASS num_put
class num_put
{       // facet for converting encoded numbers to text
public:
  typedef char _Elem;
  typedef _Ostrit _OutIt;
  typedef numpunct _Mypunct;
  typedef string _Mystr;

  typedef _Elem char_type;
  typedef _OutIt iter_type;

  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             _Bool _Val) const
  {       // put formatted bool to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }

  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             long _Val) const
  {       // put formatted long to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }

  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             unsigned long _Val) const
  {       // put formatted unsigned long to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }
#ifdef _LONGLONG
  #pragma language=save
  #pragma language=extended
  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             _LONGLONG _Val) const
  {       // put formatted long long to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }

  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             _ULONGLONG _Val) const
  {       // put formatted unsigned long long to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }
  #pragma language=restore
#endif /* _LONGLONG */

  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             double _Val) const
  {       // put formatted double to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }

  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             long double _Val) const
  {       // put formatted long double to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }

  _OutIt put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
             const void *_Val) const
  {       // put formatted void pointer to _Dest
    return (do_put(_Dest, _Iosbase, _Fill, _Val));
  }

protected:
  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         _Bool _Val) const;

  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         long _Val) const;

  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         unsigned long _Val) const;

#ifdef _LONGLONG
  #pragma language=save
  #pragma language=extended
  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         _LONGLONG _Val) const;

  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         _ULONGLONG _Val) const;
  #pragma language=restore
#endif /* _LONGLONG */

  __SOFTFP
  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         double _Val) const;

  __SOFTFP
  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         long double _Val) const;

  _VIRTUAL _OutIt do_put(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
                         const void *_Val) const;

private:
  char *_Ffmt(char *_Fmt, char _Spec,
              ios_base::fmtflags _Flags) const;

  _OutIt _Fput(_OutIt _Dest, ios_base& _Iosbase,
               _Elem _Fill, const char *_Buf,
               size_t _Beforepoint, size_t _Afterpoint,
               size_t _Trailing, size_t _Count) const;

  char *_Ifmt(char *_Fmt, const char *_Spec,
              ios_base::fmtflags _Flags) const;

  _OutIt _Iput(_OutIt _Dest, ios_base& _Iosbase, _Elem _Fill,
               char *_Buf, size_t _Count) const;

  _OutIt _Put(_OutIt _Dest, const _Elem *_Ptr, size_t _Count) const;

  _OutIt _Putc(_OutIt _Dest, const char *_Ptr, size_t _Count) const;

  _OutIt _Putgrouped(_OutIt _Dest, const char *_Ptr,
                     size_t _Count, _Elem _Kseparator) const;

  _OutIt _Rep(_OutIt _Dest, _Elem _Ch, size_t _Count) const;
};
_STD_END
#endif /* _XLOCNUM_ */

/*
 * Copyright (c) 1992-2009 by P.J. Plauger.  ALL RIGHTS RESERVED.
 * Consult your license regarding permissions and restrictions.
V5.04:0576 */
